<template>
  <div class="node" :class="`${status} ${type} ${isRoot}`">
    <img :src="imgCot.default" alt="" />
    <el-tooltip class="item" effect="dark" :content="desc? `${label}(${desc})` : label" placement="top">
      <div
        style="margin-left: 8px; cursor: pointer;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;width: 120px;">
        {{ desc? `${label}(${desc})` : label }}
      </div>
    </el-tooltip>
    <img style="margin-right: 8px" v-if="status!== 'none'" :src="imgCot[status]" alt="" />
  </div>
</template>

<script>
import Default from '@/assets/images/defaultStatus.png'
import Success from '@/assets/images/successStatus.png'
import Failed from '@/assets/images/failStatus.png'
import Running from '@/assets/images/runningStatus.png'

export default {
  name: "DatabaseCom",

  inject: ["getGraph", "getNode"],
  data() {
    return {
      status: "default",
      type: "",
      imgCot: {
        default: Default,
        success: Success,
        failed: Failed,
        running: Running,
      },
      label: "",
      desc: "",
      isRoot: "",
    };
  },
  mounted() {
    const self = this;
    const node = this.getNode();
    this.label = node.data.label;
    this.desc = node.data.statusDesc
    this.type = node.data.type;
    this.status = node.data.status;
    this.isRoot = node.data.isRoot ? "root" : ""
    // console.log("处理后节点信息详情---", this.status)
    // 监听数据改变事件
    node.on("change:data", ({ current }) => {
      console.log('变化后数据', current)
      self.label = current.label;
      self.status = current.status;
      self.desc = current.statusDesc
    });
  },
};
</script>
<style xml:lang="scss" scoped>
.node {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
  background-color: #fff;
  border: 1px solid #c2c8d5;
  border-left: 4px solid #5f95ff;
  border-radius: 4px;
  box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.06);
}

.node img {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-left: 8px;
}

.node .status {
  flex-shrink: 0;
}

.node.success {
  border-left: 4px solid #52c41a;
}

.node.failed {
  border-left: 4px solid #ff4d4f;
}

.node.root {
  background-color: rgba(103, 194, 58, 0.5);
}

.node.running .status img {
  animation: spin 1s linear infinite;
}

.x6-node-selected .node {
  border-color: #1890ff;
  border-radius: 2px;
  box-shadow: 0 0 0 4px #d4e8fe;
}

.x6-node-selected .node.success {
  border-color: #52c41a;
  border-radius: 2px;
  box-shadow: 0 0 0 4px #ccecc0;
}

.x6-node-selected .node.failed {
  border-color: #ff4d4f;
  border-radius: 2px;
  box-shadow: 0 0 0 4px #fedcdc;
}

.x6-edge:hover path:nth-child(2) {
  stroke: #1890ff;
  stroke-width: 1px;
}

.x6-edge-selected path:nth-child(2) {
  stroke: #1890ff;
  stroke-width: 1.5px !important;
}

@keyframes running-line {
  to {
    stroke-dashoffset: -1000;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
</style>
